package controllers

import (
	"github.com/goravel/framework/contracts/http"
	"github.com/goravel/framework/facades"
	"github.com/goravel/framework/support/carbon"
	"time"
)

type UserController struct {
	// Dependent services
}

func NewUserController() *UserController {
	return &UserController{
		// Inject services
	}
}

func (r *UserController) Show(ctx http.Context) http.Response {
	var name = ""
	var err error
	if !facades.Cache().Has("name") {
		name = carbon.Now().String()
		err = facades.Cache().Put("name", name, time.Minute)
		if err != nil {
			return ctx.Response().Json(http.StatusOK, http.Json{
				"message": err.Error(),
			})
		}
	} else {
		name = facades.Cache().GetString("name")
	}

	return ctx.Response().Success().Json(http.Json{
		"Hello": name,
		"Time":  carbon.Now().String(),
	})
}
